﻿using System.Linq;
using Buddy.BehaviorTree;
using Buddy.CommonBot;
using Buddy.Swtor;
using WingIt.Dynamics;

namespace WingIt.Routines
{
    public static class SithAssassin
    {
        [Class(CharacterClass.Inquisitor, AdvancedClass.Assassin, SkillTreeId.None)]
        [Behavior(BehaviorType.Combat)]
        public static Composite AssassinCombat()
        {
            return new PrioritySelector(
                Movement.StopInRange(0.3f),
                Spell.WaitForCast(),

                Spell.Cast("Mark of Power", ret => !BuddyTor.Me.HasBuff("Mark of Power")),
                
                Spell.Cast("Unbreakable Will", ret => BuddyTor.Me.IsStunned),

                // Crowd controls!
                Spell.Cast("Electrocute", onUnit => Helpers.Targets.FirstOrDefault(t => t.Toughness == CombatToughness.Strong), ret => Helpers.Targets.Count() > 3 && Helpers.Targets.FirstOrDefault(t => t.Toughness == CombatToughness.Strong) != null),
                Spell.Cast("Whirlwind", onUnit => Helpers.Targets.FirstOrDefault(t => t.Toughness == CombatToughness.Strong), ret => Helpers.Targets.Count() > 3 && Helpers.Targets.FirstOrDefault(t => t.Toughness == CombatToughness.Strong) != null),
                Spell.Cast("Low Slash", onUnit => Helpers.Targets.FirstOrDefault(t => t.Toughness == CombatToughness.Strong), ret => Helpers.Targets.Count() > 3 && Helpers.Targets.FirstOrDefault(t => t.Toughness == CombatToughness.Strong) != null),
                
                // Interrupts
                Spell.Cast("Jolt", ret => BuddyTor.Me.CurrentTarget.IsCasting),
                Spell.Cast("Overload", ret => BuddyTor.Me.CurrentTarget.IsCasting),

                // Defensive Cooldowns
                Spell.Cast("Deflection", ret => BuddyTor.Me.InCombat && BuddyTor.Me.HealthPercent <= 80),
                Spell.Cast("Force Shroud", ret => BuddyTor.Me.InCombat && BuddyTor.Me.HealthPercent <= 70),

                Spell.Cast("Discharge"),
                Spell.Cast("Wither"),
                Spell.Cast("Force Lightning"),
                Spell.Cast("Assassinate", ret => BuddyTor.Me.CurrentTarget.HealthPercent <= 30),
                Spell.Cast("Crushing Darkness", ret => BuddyTor.Me.HasBuff("Crushing Darkness")),
                Spell.Cast("Shock"),
                Spell.Cast("Thrash"),
                Spell.Cast("Saber Strike"),
                Movement.MoveTo(ret => BuddyTor.Me.CurrentTarget.Position, 0.3f)

                );
        }

        [Behavior(BehaviorType.OutOfCombat)]
        public static Composite AssassinRest()
        {
            return new PrioritySelector(
                Spell.Cast("Seethe", ret => BuddyTor.Me.HealthPercent <= 90)
                );
        }

        [Behavior(BehaviorType.Pull)]
        public static Composite AssassinPull()
        {
            return new PrioritySelector(
                Spell.Cast("Dark Charge", ret => BuddyTor.Me.CurrentTarget.Distance >= .3f));
        }
    }
}
